package com.atguigu.meinian.controller;

import com.atguigu.meinian.constant.MessageConstant;
import com.atguigu.meinian.vo.R;
import org.junit.Test;
import org.springframework.http.HttpRequest;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.core.SecurityContext;
import java.util.ArrayList;

/**
 * @author zbystart
 * @create 2021-06-26 9:23
 */
@RestController
@RequestMapping("/user")
public class UsetController {

    @GetMapping("/hello")
    public R test(HttpServletRequest request) {
        HttpSession session = request.getSession();
        return R.ok("1111",session);
    }

    @GetMapping("/getLoginUserName")
    public R getLoginUserName() {
        User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return R.ok("查询登录的用户名成功",principal.getUsername());
    }
}
